$(function () {
    //获取url
    var url = localStorage.getItem("ajaxUrl");
    var pass = 1;
    //console.log(url);

    //搜索框 获取焦点
    //board_hide("#goods_id");
    $("#goods_id").focus();

    //根据扫描内容 得到 工单
    $(document).on("keydown", "#goods_id", function (event) {
        if (event.keyCode == "13") {
            var val = $(this).val();
            $("#goods_id").blur();
            if (!val) {
                $alert("请扫描打件产品！");
                setTimeout(function () {
                    $("#goods_id").val("").focus();
                }, 1400);
                return;
            }
            //加载提示符 显示
            $(".content .list-block ul .infinite-scroll-preloader").show();
            $.ajax({
                headers: {authorization: "Bearer " + localStorage.getItem("jwt")},
                type: "post",
                url: url + '/app/split/djShangliaoSaomiao',
                data: {
                    batch: val
                },
                dataType: 'json',
                json: 'callback',
                success: function (res) {
                    //加载提示符 隐藏
                    $(".content .list-block ul .infinite-scroll-preloader").hide();
                    if (res.success) {
                        var data = res.result;
                        console.log(data);
                        localStorage.setItem("djgd", JSON.stringify(data));
                        //获取 成功 跳转页面
                        window.location.href = "pack_one.html";
                    } else {
                        setTimeout(function () {
                            $("#goods_id").val("").focus();
                        }, 1400);
                        $alert(res.message);
                    }
                },
                error: function (error) {
                    //加载提示符 隐藏
                    $(".content .list-block ul .infinite-scroll-preloader").hide();
                    console.log(error);
                    setTimeout(function () {
                        $("#goods_id").val("").focus();
                    }, 1400);
                    $alert(error.responseText);
                }
            });
        }
    });

});
